var autoIncrement = require('mongoose-auto-increment')
var mongoose = require('mongoose');
var schema = mongoose.Schema;
var core = require('core');

var Order = function(){
    var orderSchema = new schema({
        oid : { type: String, index: true, default : function(){
            var date = new Date();
            var oid = "WRHJ_";
            var day = date.getDate();
            var month = date.getMonth() + 1;
            var year = date.getFullYear();

            oid += year + "" + (month < 10 ? "0" + month : month) + "" + (day < 10 ? "0" + day : day) + "" +date.getTime();

            return oid;
        } },
        money : { type: Number },
        mid : { type: Number },
        openid : { type: String },
        body : { type: String },
        sale : { type: String },
        runMoney : { type: Number },
        status : { type: Boolean, default: false },
        auth_status : { type: Boolean, default: false },
        transaction_id : { type: String },
        create_time : { type: Date, default: Date.now },
        pay_time: { type: Date },
        auth_time : { type: Date }
    });

    return mongoose.model('Order',orderSchema, 'Order');
};

module.exports = Order;
